﻿using System;

namespace PageAdmin.Utils
{
    /// <summary>
    /// 全局过滤器特性，只能用于方法上,而且方法必须为public类型的带一个参数的静态方法，参数类型为：ActionExecutingContext，ActionExecutedContext，ResultExecutingContext，ResultExecutedContext中的一种
    /// </summary>
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
    public class GlobalActionFilterAttribute : Attribute
    {
        /// <summary>
        /// 要监听的方法集合,格式:命名空间.类.方法名
        /// </summary>
        public virtual string[] WatcherActions { get; set; }

        /// <summary>
        /// 请求类型，如POST,GET
        /// </summary>
        public virtual string[] RequestTypes { get; set; }

        /// <summary>
        /// 路径键值
        /// </summary>
        public virtual string[] RouteValues { get; set; }

        /// <summary>
        /// 区域
        /// </summary>
        public virtual string[] Areas { get; set; }

        /// <summary>
        /// 全局过滤器特性
        /// </summary>
        /// <param name="watcherActions">方法数组约束,不设置则不进行约束</param>
        /// <param name="requestTypes">请求类型数组约束,不设置则不进行约束</param>
        /// <param name="routeValues">RouteData.Values键值（RouteData.Values）约束数组,可对url相关的路由值进行约束，不设置则不进行约束</param>
        /// <param name="areas">区域数组约束,不设置则不进行约束</param>
        public GlobalActionFilterAttribute(string[] watcherActions = null,string[] requestTypes = null,string[] routeValues = null, string[] areas = null)
        {
            this.WatcherActions = watcherActions;
            this.RequestTypes = requestTypes;
            this.RouteValues = routeValues;
            this.Areas = areas;
        }
    }
}